package edu.noteBook.service.impl;

import edu.noteBook.Pojo.User;
import edu.noteBook.dao.UserDao;
import edu.noteBook.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Override
    public User login(String username, String password) {
        return userDao.login(username,password);
    }

    @Override
    public List<User> queryUser(String username, String email) {
        return userDao.queryUser(username,email);
    }

    @Override
    public boolean addUser(User user) {
        User user1 = userDao.queryUserByEmail(user.getEmail());
        if(user1!=null){
            return false;
        }else{
            return userDao.addUser(user) > 0;
        }
    }

    @Override
    public boolean deleteUser(Integer id) {
        if(userDao.deleteUser(id) > 0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public User queryUserByID(Integer id) {
        return userDao.queryUserById(id);
    }

    @Override
    public int updateUser(User user) {
        return userDao.updateUser(user);
    }
}
